﻿/************************************************************************

   Extended Silverlight Toolkit

   Copyright (C) 2010-2012 Xceed Software Inc.

   This program is provided to you under the terms of the Microsoft Public
   License (Ms-PL) as published at http://extendedsilverlight.codeplex.com/license

   Please purchase a commercial version of this toolkit if you are using
   it in a commercial product. The commercial versions support the project,
   and also include more features for each control, priority support,
   source code, updates, removed watermark, and a proprietary license.

   Visit http://xceed.com and follow @datagrid on Twitter.

  **********************************************************************/

using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Media;

// Original code comments:
// PathGeometryHelper.cs by Charles Petzold, December 2007
//
// This source code obtained from MSDN Magasine Code Foundation (March 2008) and 
// the URL is http://msdn.microsoft.com/en-us/magazine/cc337985.aspx?code=true&level=root,Petzold.Shapes&file=PathGeometryHelper.cs.

namespace Xceed.Silverlight.Utils
{
  internal static class GeometryHelper
  {
    public static List<Point> GetPointsOnFlattenedPath( PathGeometry flattenedPath )
    {
      List<Point> flattenedPathPoints = new List<Point>();

      // For flattened geometry there should be just one PathFigure in the Figures
      if( flattenedPath.Figures.Count != 1 )
        return new List<Point>();

      PathFigure pathFigure = flattenedPath.Figures[ 0 ];

      flattenedPathPoints.Add( pathFigure.StartPoint );

      // SegmentsCollection should contain PolyLineSegment and LineSegment
      foreach( PathSegment pathSegment in pathFigure.Segments )
      {
        if( pathSegment is PolyLineSegment )
        {
          PolyLineSegment seg = pathSegment as PolyLineSegment;
          flattenedPathPoints.AddRange( seg.Points );
        }
        else if( pathSegment is LineSegment )
        {
          LineSegment seg = pathSegment as LineSegment;
          flattenedPathPoints.Add( seg.Point );
        }
        else
        {
          throw new Exception( "GetIntersectionPoint - unexpected path segment type: " + pathSegment.ToString() );
        }
      }

      return ( flattenedPathPoints );
    }
  }
}
